﻿using ARchGL.Platform.Sessions;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
using WebApiClient.Attributes;
using WebApiClient.Contexts;

namespace ARchGL.Platform.Mpp
{
    public class DefaultHeaderAttribute : ApiActionFilterAttribute
    {
        private IConfigurationRoot appConfiguration;

        public DefaultHeaderAttribute(IConfigurationRoot _appConfiguration)
        {
            appConfiguration = _appConfiguration;
        }

        public override async Task OnBeginRequestAsync(ApiActionContext context)
        {
            string accessToken = RefreshTokenService.GetAccessToken();
            context.RequestMessage.Headers.Add("Authorization", accessToken);
            await base.OnBeginRequestAsync(context);
        }

        public override Task OnEndRequestAsync(ApiActionContext context)
        {
            var msg = context.ResponseMessage;

            return base.OnEndRequestAsync(context);
        }
    }
}
